package com.company;

//定义宠物猫子类
class Cat implements Pet{
    private String name;
    private int age;
    public Cat(String name,int age){
        this.name=name;
        this.age=age;
    }
    public boolean equals(Object obj){
        if (this==obj){
            return true;
        }
        if (obj==null){
            return false;
        }
        if (!(obj instanceof Cat)){
            return false;
        }
        Cat c=(Cat) obj;
        if (this.name.equals(c.name)&&this.age==c.age){
            return true;
        }
        return false;
    }

    public String getName() {   //覆写接口的方法
        return this.name;
    }
    public int getAge() {       //覆写接口的方法
        return this.age;
    }
    public String toString(){
        return "猫的名字："+this.name+",年龄："+this.age;
    }
}
//定义宠物狗子类
class Dog implements Pet{
    private String name;
    private int age;
    public Dog(String name,int age){
        this.name=name;
        this.age=age;
    }
    public boolean equals(Object obj){
        if (this==obj){
            return true;
        }
        if (obj==null){
            return false;
        }
        if (!(obj instanceof Dog)){
            return false;
        }
        Dog c=(Dog) obj;
        if (this.name.equals(c.name)&&this.age==c.age){
            return true;
        }
        return false;
    }

    public String getName() {   //覆写接口的方法
        return this.name;
    }
    public int getAge() {       //覆写接口的方法
        return this.age;
    }
    public String toString(){
        return "狗的名字："+this.name+",年龄："+this.age;
    }
}